<?php

namespace App\Http\Requests\System;

use App\Http\Requests\BaseRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class Employee extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id_no' =>[
                'required',
                Rule::unique('employees')
                ->ignore(request()->id)
                ->whereNull('deleted_at')
            ],
            'id_type' => 'required',
            'name' => 'required',
            'birthday' => 'required',
            'phone' => 'required|regex:/^1[345789][0-9]{9}$/',
            'education' => 'required',
            'age' => 'required',
            'address' => 'required',
            'nation' => 'required',
            'bank_name' => 'required',
            'account' => 'required',
            'emergency_contact' => 'required',
            'emergency_relation' => 'required',
            'emergency_phone' => 'required|regex:/^1[345789][0-9]{9}$/',
        ];
    }

    public function messages()
    {
        return [
            'id_no.required' => "请输入员工证件号码",
            'id_no.unique' => "员工证件号码重复",
            'it_type.required' => '请输入员工证件类型',
            'name.required' => '请输入员工姓名',
            'birthday.required' => '请输入员工生日',
            'phone.required' => '请输入员工电话',
            'phone.regex' => '员工电话格式不合法',
            'education.required' => '请输入员工学历',
            'age.required' => '请输入员工年龄',
            'address.required' => '请输入员工住址',
            'nation.required' => '请输入员工民族',
            'bank_name.required' => '请输入开户名',
            'account.required' => '请输入开户账号',
            'emergency_contact.required' => '请输入紧急联系人',
            'emergency_relation.required' => '请输入紧急联系人关系',
            'emergency_phone.required' => '请输入紧急联系人电话',
            'emergency_phone.regex' => '紧急联系人电话格式不合法',
        ];
    }
}
